from django.db import models

from user.models import User

# Create your models here.
class Car(models.Model):
    manufacturers = models.CharField(max_length=50, null=True)
    carname = models.CharField(max_length=50, null=True)
    points = models.CharField(max_length=10, null=True)
    guideprice = models.CharField(max_length=50, null=True)
    msg = models.CharField(max_length=255, null=True)
    errormsg = models.JSONField( null=True)
    Second_hand_prices= models.FloatField(verbose_name='二手价格',null=True)
    hot = models.IntegerField(verbose_name='热度',null=True)
    Radar_chart =  models.JSONField(null=True, verbose_name='雷达图')
    key_word =  models.JSONField(null=True, verbose_name='关键词')
    c_img_url = models.CharField(max_length=255, null=True, verbose_name='汽车图片')

    def __str__(self):
        return f'{self.manufacturers} - {self.carname}'
    class Meta:
        app_label = 'car'
        verbose_name = '汽车信息'
        verbose_name_plural = verbose_name
class CarInfo(models.Model):
    id = models.IntegerField(primary_key=True, verbose_name='汽车ID')
    b_id = models.IntegerField(verbose_name='品牌ID')
    s_id = models.IntegerField(verbose_name='车系ID')
    b_name = models.CharField(max_length=50, verbose_name='品牌名')
    c_series_name = models.CharField(max_length=50, verbose_name='车系')
    c_spec_name = models.CharField(max_length=100, verbose_name='车型')
    c_level = models.CharField(max_length=50, null=True, verbose_name='级别')
    c_engine = models.CharField(max_length=50, null=True, verbose_name='发动机/排量')
    c_gearbox = models.CharField(max_length=50, null=True, verbose_name='变速箱')
    c_structure = models.CharField(max_length=50, null=True, verbose_name='车身结构')
    c_electric_engine = models.CharField(max_length=50, null=True, verbose_name='电动机')
    c_endurance_mileage = models.CharField(max_length=50, null=True, verbose_name='续航里程')
    c_fuel_consump = models.CharField(max_length=50, null=True, verbose_name='综合油耗(工信部)')
    c_max_torque = models.CharField(max_length=50, null=True, verbose_name='最大扭矩')
    c_envi_stan = models.CharField(max_length=50, null=True, verbose_name='环保标准')
    c_max_power = models.CharField(max_length=50, null=True, verbose_name='最大功率')
    c_energy_type = models.CharField(max_length=50, null=True, verbose_name='能源类型')
    c_slow_charging_time = models.CharField(max_length=50, null=True, verbose_name='慢充时间')
    c_fast_charging_time = models.CharField(max_length=50, null=True, verbose_name='快充时间')
    car = models.ForeignKey(Car,on_delete=models.CASCADE)
    def __str__(self):
        return f'{self.b_name} - {self.c_series_name}'

    class Meta:
        db_table = 'carhouse_car_info'
        app_label = 'car'
        verbose_name = '汽车小类信息'
        verbose_name_plural = verbose_name
class CarsComment(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    time = models.DateTimeField(auto_now_add=True,verbose_name='发布时间')
    points = models.IntegerField(verbose_name='评分',null=True)
    title = models.CharField(max_length=50, verbose_name='标题')
    c_series_name = models.CharField(max_length=50, verbose_name='车系',null=True)
    c_spec_name = models.CharField(max_length=50, verbose_name='车型',null=True)
    address = models.CharField(max_length=100, null=True, verbose_name='购车地')
    mileage = models.CharField(max_length=50,verbose_name='里程/km',null=True)
    fuel = models.CharField (max_length=50,verbose_name='百公里油耗',null=True)
    price = models.CharField(max_length=50,verbose_name='购买价格/万元',null=True)
    buy_time = models.CharField(max_length=50,verbose_name='购车日期',null=True)
    satisfied = models.TextField(verbose_name='满意',null=True)
    dissatisfied = models.TextField(verbose_name='不满意',null=True)
    car = models.ForeignKey(Car,on_delete=models.CASCADE)

    def __str__(self):
        return self.title  # 在管理界面中显示用户的用户名
    class Meta:
        app_label = 'car'
        verbose_name = '车辆评论'
        verbose_name_plural = verbose_name